package cn.stylefeng.guns.modular.gridsystem.temperature.controller;

import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.guns.core.annotion.BusinessLog;
import cn.stylefeng.guns.core.enums.LogAnnotionOpTypeEnum;
import cn.stylefeng.guns.core.pojo.base.param.BaseParam;
import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.core.pojo.response.SuccessResponseData;
import cn.stylefeng.guns.modular.gridsystem.model.param.BizGatewayChannelParam;
import cn.stylefeng.guns.modular.gridsystem.temperature.model.param.BizTemperatureChannelParam;
import cn.stylefeng.guns.modular.gridsystem.temperature.model.param.BizTemperatureRecordParam;
import cn.stylefeng.guns.modular.gridsystem.temperature.service.BizTemperatureChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.ws.soap.Addressing;

@RestController
public class BizTemperatureChannelController {

    @Autowired
    private BizTemperatureChannelService bizTemperatureChannelService;


    /**
     * 根据网关ID 获取温度的通道
     *
     * @param param
     * @return
     */
    @GetMapping("/temperature/channel/tempChannelList")
    @BusinessLog(title = "网关Id查询通道", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData getTempChannelList(BizTemperatureChannelParam param) {
        if (ObjectUtil.isEmpty(param.getGatewayId())) {
            return ResponseData.error("网关id不能为空！");
        }
        return new SuccessResponseData(bizTemperatureChannelService.getTempChannelList(param));
    }


    /**
     * 添加
     *
     * @param param
     * @return
     */
    @PostMapping("/temperature/channel/add")
    @BusinessLog(title = "biz_temperature_channel_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@RequestBody @Validated({BizTemperatureChannelParam.add.class}) BizTemperatureChannelParam param) {

        bizTemperatureChannelService.toAdd(param);
        return new SuccessResponseData();
    }

    /**
     * 编辑
     *
     * @param param
     * @return
     */
    @PostMapping("/temperature/channel/edit")
    @BusinessLog(title = "biz_temperature_channel_修改", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody @Validated({BizTemperatureChannelParam.edit.class}) BizTemperatureChannelParam param) {

        bizTemperatureChannelService.toEdit(param);
        return new SuccessResponseData();
    }

    /**
     * 删除
     *
     * @param param
     * @return
     */
    @PostMapping("/temperature/channel/delete")
    @BusinessLog(title = "biz_temperature_channel_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody @Validated({BaseParam.delete.class}) BizTemperatureChannelParam param) {

        bizTemperatureChannelService.toDelete(param);
        return new SuccessResponseData();
    }


}
